package org.upt.dcda.db;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The persistent class for the books database table.
 * 
 */
@Entity
@Table(name = "books")
@NamedQueries(value = {
		@NamedQuery(name = BookEntity.GET_BOOKS_BY_TAGS_QUERY, query = "SELECT DISTINCT book FROM BookEntity book, BookTagEntity bte, TagEntity tag WHERE bte.book = book AND bte.tag = tag AND tag.tagName IN (:tags)"),
		@NamedQuery(name = BookEntity.GET_ALL_BOOKS_QUERY, query = "SELECT book FROM BookEntity book") })
@NamedNativeQuery(name = BookEntity.SEARCH_BY_BOOK_TITLE, resultClass = BookEntity.class, query = "SELECT * FROM books WHERE MATCH (`book_title`) AGAINST (:key)")
public class BookEntity implements Serializable
{

	public static final String		GET_BOOKS_BY_TAGS_QUERY	= "get_books_by_tags_query";

	public static final String		GET_ALL_BOOKS_QUERY		= "get_all_books_query";

	public static final String		SEARCH_BY_BOOK_TITLE	= "search_by_book_title_query";

	private static final long		serialVersionUID		= 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "book_id")
	private int						bookId;

	@Column(name = "book_description")
	private String					bookDescription;

	@Column(name = "book_price")
	private int						bookPrice;

	@Column(name = "book_quantity")
	private int						bookQuantity;

	@Column(name = "book_title")
	private String					bookTitle;

	@ManyToOne(cascade = CascadeType.REMOVE)
	@JoinColumn(name = "book_author_id")
	private AuthorEntity			author;

	@OneToMany(mappedBy = "book")
	private Set<NotificationEntity>	notifications;

	@OneToMany(mappedBy = "book")
	private Set<OrderItemEntity>	orderitems;

	@OneToMany(mappedBy = "book")
	private Set<BookTagEntity>		booktags;

	@OneToMany(mappedBy = "book")
	private Set<BookReviewEntity>	bookreviews;

	public BookEntity()
	{
	}

	public int getBookId()
	{
		return this.bookId;
	}

	public void setBookId(int bookId)
	{
		this.bookId = bookId;
	}

	public String getBookDescription()
	{
		return this.bookDescription;
	}

	public void setBookDescription(String bookDescription)
	{
		this.bookDescription = bookDescription;
	}

	public int getBookPrice()
	{
		return this.bookPrice;
	}

	public void setBookPrice(int bookPrice)
	{
		this.bookPrice = bookPrice;
	}

	public int getBookQuantity()
	{
		return this.bookQuantity;
	}

	public void setBookQuantity(int bookQuantity)
	{
		this.bookQuantity = bookQuantity;
	}

	public String getBookTitle()
	{
		return this.bookTitle;
	}

	public void setBookTitle(String bookTitle)
	{
		this.bookTitle = bookTitle;
	}

	// bi-directional many-to-one association to AuthorEntity

	public AuthorEntity getAuthor()
	{
		return this.author;
	}

	public void setAuthor(AuthorEntity author)
	{
		this.author = author;
	}

	// bi-directional many-to-one association to NotificationEntity

	public Set<NotificationEntity> getNotifications()
	{
		return this.notifications;
	}

	public void setNotifications(Set<NotificationEntity> notifications)
	{
		this.notifications = notifications;
	}

	// bi-directional many-to-one association to OrderItemEntity

	public Set<OrderItemEntity> getOrderitems()
	{
		return this.orderitems;
	}

	public void setOrderitems(Set<OrderItemEntity> orderitems)
	{
		this.orderitems = orderitems;
	}

	// bi-directional many-to-one association to BookTagEntity

	public Set<BookTagEntity> getBooktags()
	{
		return this.booktags;
	}

	public void setBooktags(Set<BookTagEntity> booktags)
	{
		this.booktags = booktags;
	}

	// bi-directional many-to-one association to BookReviewEntity

	public Set<BookReviewEntity> getBookreviews()
	{
		return this.bookreviews;
	}

	public void setBookreviews(Set<BookReviewEntity> bookreviews)
	{
		this.bookreviews = bookreviews;
	}

}
